package com.rain.friend.dao;

import com.rain.friend.pojo.Friend;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 交友的持久层接口
 */
public interface FriendDao extends JpaRepository<Friend,String> {

    /**
     * 根据用户id和朋友id查询交友表的记录数
     * @param userid
     * @param friendid
     * @return
     */
    @Query("select count(f) from Friend f where f.userid = ?1 and f.friendid = ?2 ")
    int selectCount(String userid, String friendid);

    /**
     * 根据用户id和交友id更新islike字段
     * @param userid
     * @param friendid
     * @param islike
     * @return
     */
    @Query("update Friend f set f.islike = ?3 where f.userid = ?1 and f.friendid = ?2 ")
    @Modifying
    void updateIsLike(String userid, String friendid, String islike);

    /**
     * 删除关注
     * @param userid
     * @param friendid
     * @return
     */
    @Query("delete from Friend  f where f.userid =?1 and f.friendid=?2 ")
    @Modifying
    void deleteFriend(String userid, String friendid);
}
